package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.domain.SystemDictionaryItem;
import cn.congzhou.crm.mapper.SystemDictionaryItemMapper;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {

    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        if(id!=null){
            systemDictionaryItemMapper.deleteByPrimaryKey(id);
        }
        return 0;
    }


    @Override
    public SystemDictionaryItem selectByPrimaryKey(Long id) {
        SystemDictionaryItem sysDicItem = systemDictionaryItemMapper.selectByPrimaryKey(id);
        return sysDicItem;
    }

    @Override
    public List<SystemDictionaryItem> selectAll() {
        List<SystemDictionaryItem> sysDicItem = systemDictionaryItemMapper.selectAll();
        return sysDicItem;
    }

    @Override
    public void saveOrUpdate(SystemDictionaryItem sysDicItem) {
        if(sysDicItem.getId()!=null){
            systemDictionaryItemMapper.updateByPrimaryKey(sysDicItem);
        }else {
            systemDictionaryItemMapper.insert(sysDicItem);
        }
    }

//    分页查询
    @Override
    public PageInfo<SystemDictionaryItem> selectByPage(QueryObject qo) {
//      调用这个类的静态方法处理分页数据
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"sequence desc");
        List<SystemDictionaryItem> list = systemDictionaryItemMapper.selectByPage(qo);
//      创建页面信息对象封装起来
        PageInfo<SystemDictionaryItem> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //查询所有工作
    @Override
    public List<SystemDictionaryItem> selectAllJobs() {
        List<SystemDictionaryItem> jobs = systemDictionaryItemMapper.selectAllJobs();
        return jobs;
    }

    //查询所有来源
    @Override
    public List<SystemDictionaryItem> selectAllSources() {
        List<SystemDictionaryItem> sources = systemDictionaryItemMapper.selectAllSources();
        return sources;
    }

    @Override
    public List<SystemDictionaryItem> selectAllTypes() {
        return systemDictionaryItemMapper.selectAllTypes();
    }

    @Override
    public SystemDictionaryItem selectByName(String curriculumStr) {
        return systemDictionaryItemMapper.selectByName(curriculumStr);
    }

    @Override
    public List<SystemDictionaryItem> selectAllCurriculum(String curriculum) {
        return systemDictionaryItemMapper.selectAllCurriculum(curriculum);
    }
}
